import requests

# response = requests.get("https://www.baidu.com")

# # 1. 检查请求是否成功
# if response.status_code == 200:
#     print("成功！")
# else:
#     print("失败！状态码：", response.status_code)
#
# # 或者直接抛出异常（如果状态码不是 200-399）
# response.raise_for_status()

# data = {"key": "value"}
# response = requests.post("https://httpbin.org/post", json=data)
# # 2. 解析 JSON
# res_json = response.json()
# print(response.json())
# print(res_json['data'])


# 3. 下载文件
url = "http://www.zlcode.top/assets/logo-B-2-KWlx.png"
response = requests.get(url)

with open("image.jpg", "wb") as f:
    f.write(response.content)  # 二进制内容写入文件
